<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Model;

use HyperfExtension\Jwt\Contracts\JwtSubjectInterface;

/**
 * @property int $id 
 * @property string $nick_name 
 * @property string $real_name 
 * @property string $avatar 
 * @property string $mobile 
 * @property string $sex 
 * @property string $address 
 * @property string $birthday 
 * @property string $password_plaintext 
 * @property string $password 
 * @property string $user_agent 
 * @property string $last_login_ip 
 * @property string $last_login_at 
 * @property string $invite_code 
 * @property string $register_id 
 * @property int $is_ban 
 * @property int $is_share 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property string $deleted_at 
 * @property string $activity_invite_code 
 * @property int $is_share_commission 
 */
class User extends Model implements JwtSubjectInterface
{
    public const APP_LOGIN_KEY = 'app_user';

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'users';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'nick_name', 'real_name', 'avatar', 'mobile', 'sex', 'address', 'birthday', 'password_plaintext', 'password', 'user_agent', 'last_login_ip', 'last_login_at', 'invite_code', 'register_id', 'is_ban', 'is_share', 'created_at', 'updated_at', 'deleted_at', 'activity_invite_code', 'is_share_commission'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'is_ban' => 'integer', 'is_share' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'is_share_commission' => 'integer'];

    protected array $appends = [];

    public function getJwtIdentifier()
    {
        return $this->getKey();
    }

    public function getJwtCustomClaims(): array
    {
        return [];
    }
//    public function updated(Updated $event)
//    {
//        if ($event->getModel()->level > $event->getModel()->max_level) {
//
//            $this->max_level = $event->getModel()->level;
//            $this->save();
//        }
//    }

//    public function saving(Saving $event)
//    {
//        $this->setNickName('2019-01-01');
//    }


//     public function getLevelAttribute()
//     {
//        return 1;
//    }
}
